﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Configuration;
using DropBoxClient.Entities;
using System.IO;

namespace DropBoxClient.Tests
{
    [TestClass]
    [DeploymentItem("Data\\UploadThisFile.txt")]
    public class PutFilesTest
    {
        private string accessToken;
        private OAuth2Client client;
        private Meta meta;
        private string inputFilePath;

        private static readonly string FileName = "UploadThisFile.txt";
        private static readonly string PathName = "Test/UploadThisFile.txt";

        public TestContext TestContext { get; set; }

        [TestInitialize]
        public void Init()
        {
            accessToken = ConfigurationManager.AppSettings["AccessToken"];
            client = new OAuth2Client(accessToken);
            inputFilePath = Path.Combine(TestContext.DeploymentDirectory, FileName);
            meta = client.PutFiles(StringConstants.SandboxRoot, PathName, inputFilePath);
        }

        [TestMethod]
        public void PutFiles_ResultIsNotNull()
        {
            Assert.IsNotNull(meta);
        }

        [TestMethod]
        public void PutFiles_PathIsCorrect()
        {
            Assert.AreEqual("/" + PathName, meta.Path);
        }

        [TestMethod]
        public void PutFiles_SizeIsCorrect()
        {
            var stream = File.Open(inputFilePath, FileMode.Open);
            long fileSize = stream.Length; 
            Assert.AreEqual(fileSize, meta.Bytes);
        }

        [TestCleanup]
        public void Cleanup()
        {
            client.Delete(StringConstants.SandboxRoot, PathName);
        }
    }
}
